package dwei.ui
{
	
	import flash.display.StageAlign;
	import flash.display.StageScaleMode;
	import flash.events.Event;
	import dwei.ui.core.ValidateMgr;
	import dwei.ui.core.ValidateSprite;

	public class UIStage extends ValidateSprite
	{
//============================================================================
//CONSTRUCTOR
//============================================================================
		public function UIStage()
		{
			super();
			nestLevel = 1;
			
			addEventListener(Event.ADDED_TO_STAGE, addedToStage_handler);
		}
//============================================================================
//METHOD
//============================================================================
		override protected function createChildren():void
		{
			super.createChildren();
		}
		override protected function measure():void
		{
			super.measure();
			setActualSize(stage.stageWidth, stage.stageHeight);
		}
		override protected function updateDisplayList():void
		{
			graphics.clear();
			graphics.lineStyle(3, 0x00ff00, 0.9);
			graphics.drawRect(1, 1, width - 3, height - 3);
			graphics.endFill();
		}
//============================================================================
//HANDLER
//============================================================================
		private function addedToStage_handler(event:Event):void
		{
			removeEventListener(Event.ADDED_TO_STAGE, addedToStage_handler);
			
			stage.align = StageAlign.TOP_LEFT;
			stage.scaleMode = StageScaleMode.NO_SCALE;
			stage.addEventListener(Event.RESIZE, stageResize_handler);
			
			ValidateMgr.initialize(stage);
			UIMgr.initialze(this);
			
			initialize();
		}
		private function stageResize_handler(event:Event):void
		{
			invalidateSize();
		}
	}
}